
# 锋利问题

# 交叉熵与KL

# 为什么不能直接计算，链式法则


import numpy as np
import matplotlib.pyplot as plt
# python image library python图像处理库
from PIL import Image
from torchvision import transforms, datasets


# img = plt.imread(r"D:\\Photos\\daily\\1655783314442.jpg")
# # print(img)
# # plt.imshow(img)
# # plt.show()
# #
# img2 = Image.open(r"D:\\Photos\\daily\\1655783314442.jpg")
# img2.show()
# #
# # img3 = Image.open(r"D:\\Photos\\daily\\1655783314442.jpg")
# # img3 = img3.convert('L')
# # img3.show()
#
# # 不推荐这种方式转化为tensor
# # imgtsr = torch.tensor(img)
# # print(type(imgtsr))
# # h w c
# print(img.shape)
#
# print(type(img2))
#
# np.transpose(img, (2, 0, 1))
# print(img.shape)

# c h w
img = plt.imread(r"D:\\Photos\\daily\\1655783314442.jpg")
imgtr = transforms.ToTensor()(img)
resize = transforms.Resize((360, 360))
resize(imgtr)
print(type(imgtr))
print(imgtr.shape)
# print(imgtr)

# 对图片进行多次操作
pipline = transforms.Compose([transforms.ToTensor(), transforms.Resize((500, 500))])
imgline = pipline(img)
print(type(imgline))

p = transforms.Compose([transforms.ToTensor(), transforms.Normalize([0.5], [0.5])])

d = datasets.MNIST('../data', transform=p, train=True, download=True)
# print(d[1888])
print(d[666][0].min())
imgx = transforms.ToPILImage()(d[666][0])
# print(d)
